package com.comast.eep.bridge;

import java.util.List;
import java.util.Map;

import javax.jms.JMSException;
import javax.jms.Message;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.comast.eep.bridge.jms.JMSSender;
import com.comcast.eep.bridge.common.EEPBridgeUtils;
import com.comcast.eep.bridge.dao.ConsumerDAO;
import com.comcast.eep.bridge.model.Consumer;

public class EEPBridgeImpl {
	
	private static final Log logger = LogFactory.getLog(EEPBridgeImpl.class);
	
	public String persist(Message msg) throws JMSException {

		List<String> cons = EEPBridgeUtils.trimConsumer(msg.getStringProperty("CONSUMERS"));
		
		if(logger.isDebugEnabled()) {
			logger.debug("MCons:"+ cons );
		}

		Map<String, Consumer> consumers = consumerdao.getConsumer(cons);
		
		if(logger.isDebugEnabled()) {
			logger.debug("Consumers:" + consumers);
		}
		
		return jmsSender.sendMessage(msg, consumers);
	}
	
	private JMSSender jmsSender;
	
	public JMSSender getJmsSender() {
		return jmsSender;
	}

	public void setJmsSender(JMSSender jmsSender) {
		this.jmsSender = jmsSender;
	}

	private ConsumerDAO consumerdao;

	public ConsumerDAO getConsumerdao() {
		return consumerdao;
	}

	public void setConsumerdao(ConsumerDAO consumerdao) {
		this.consumerdao = consumerdao;
	}
	
}
